const http = require('http');

const fs = require('fs');

http.createServer((req,res)=>{

    let url = new URL(req.url,"http://localhost");

    // 判断请求路径
    if(url.pathname === '/'){
        fs.readFile(__dirname+'/index.html',(err,data)=>{
            if(err){
                console.log("读取失败");
            }else{
                res.end(data);
            }
        });
    }else if(url.pathname === '/css/style.css'){
        fs.readFile(__dirname+'/css/style.css',(err,data)=>{
            if(err){
                console.log("读取失败");
            }else{
                res.end(data);
            }
        });
    }
    
    // res.end('<h1 style="color:red">欢迎来到我的小站</h1>');

}).listen(80,()=>{
    console.log("80端口服务已起动");
});